
#include "VolumeUnit.h"
#include <sstream>

const unsigned int TBSP_TO_TBSP(1);
const unsigned int TSP_TO_TBSP(4);
const unsigned int OZ_TO_TBSP(3 * TSP_TO_TBSP);

const UnitType  UnitTypeVolume;
const VolumeUnit OZ(OZ_TO_TBSP, UnitTypeVolume);
const VolumeUnit TSP(TSP_TO_TBSP, UnitTypeVolume);
const VolumeUnit TBSP(TBSP_TO_TBSP, UnitTypeVolume);

VolumeUnit::VolumeUnit(unsigned int unit, const UnitType &unitType)
:
Unit(unit, unitType)
{
}

string VolumeUnit::formatToString(unsigned int amount) const
{
	unsigned int amoutInBaseUnit = getValueInBaseUnit(amount);

	if(0 == amoutInBaseUnit)
	{
		return string("0 TBSP");
	}
	unsigned int oz = amoutInBaseUnit / OZ_TO_TBSP;
	stringstream tmpStr;
	if(0 != oz)
	{
        tmpStr << oz <<" OZ";
	}
	unsigned int tsp = amoutInBaseUnit % OZ_TO_TBSP / TSP_TO_TBSP;
	if(0 != tsp)
	{
        if(0 != oz)
        {
            tmpStr << " ";
        }
		tmpStr << tsp << " TSP";
	}
	unsigned int tbsp = amoutInBaseUnit % TSP_TO_TBSP;
	if(0 != tbsp)
	{
        if(0 != oz || 0 != tsp)
        {
            tmpStr << " ";
        }
		tmpStr << tbsp << " TBSP";
	}
	return tmpStr.str();
}
string VolumeUnit::getBaseUnitName() const
{
    return string("TBSP");
}

